<!--
 * @Description: Description
 * @Author: Kerwin
 * @Date: 2025-02-27 14:14:56
 * @LastEditTime: 2025-03-15 15:20:17
 * @LastEditors:  Please set LastEditors
-->
<template>
  <!-- 自定义图片弹窗 -->
  <view class="custom-modal" @click="hideImage" v-if="showImage">
    <image src="../../static/箭头.png"     class="share-image" />
  </view>
</template>

<script>
export default {
  data() {
    return {
      showImage: false
    }
  },
  methods: {
    show() {
      this.showImage = true;
      // this.addWxShareParam();
      // setTimeout(() => this.hideImage(), 3000); // 3秒后自动关闭
    },
    hideImage() {
      this.showImage = false;
      // this.removeWxShareParam();
    },
    addWxShareParam() {
      const url = new URL(window.location.href);
      const hash = url.hash;
      const hashParts = hash.split('?');
      const path = hashParts[0];
      let queryParams = new URLSearchParams(hashParts[1]);

      const idParam = queryParams.get('id');
      // 确保 wxShare 参数只添加一次
      if (queryParams.has('wxShare')) return
      if (idParam) {
        if (!idParam.includes('wxShare=1')) {
          queryParams.set('id', `${idParam}&wxShare=1`);
        }
      } else {
        queryParams.set('wxShare', '1');
      }



      // 手动处理 hash 部分，避免 URLSearchParams 编码
      const newHash = `${path}?${queryParams.toString().replace(/%26/g, '&').replace(/%3D/g, '=')}`;
      url.hash = newHash;
      window.history.replaceState({}, '', url.toString());
    },
    removeWxShareParam() {
      const url = new URL(window.location.href);
      const hash = url.hash;
      const hashParts = hash.split('?');
      const path = hashParts[0];
      let queryParams = new URLSearchParams(hashParts[1]);

      const idParam = queryParams.get('id');
      if (idParam) {
        const newIdParam = idParam.replace(/&wxShare=1/, '');
        queryParams.set('id', newIdParam);
      }
      queryParams.delete('wxShare');

      // 手动处理 hash 部分，避免 URLSearchParams 编码
      const newHash = `${path}?${queryParams.toString().replace(/%26/g, '&').replace(/%3D/g, '=')}`;
      url.hash = newHash;
      window.history.replaceState({}, '', url.toString());
    }
  }
}
</script>

<style>
.custom-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  /* background: url("../../static/箭头.png"); */
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.share-image {
  width: 800rpx;
 
  position: fixed;
  top: 0;
left: 80rpx;
  animation: scaleIn 0.3s ease;
}

@keyframes scaleIn {
  from {
    transform: scale(0.8);
  }

  to {
    transform: scale(1);
  }
}
</style>